<?php

/**
* Milestones Controller
*/
class MilestonesController extends AppController
{
	var $name = 'Milestones';
	var $helpers = array('Html', 'Form', 'Javascript', 'Ajax');
	var $components = array('UserAuth', 'RequestHandler');

	function beforeFilter( ) {
	    if ($this->RequestHandler->isAjax()) {
	        $db =& ConnectionManager::getDataSource('default');
	        $db->fullDebug = false;
	    }
	}
	
	public function view($id)
	{
		$this->set('project_id', 0);
		$this->set('project_name', "");
		$this->set('Milestones', $this->Milestone->findAllBybatch_id($id));
	}
	
	public function add() {
		if (empty($this->data) == false) {
//			pr($this->data['Milestone']);
			$milestone = array('Milestone' => array('batch_id' => 0, 'name' => $this->data['Milestone']['name']));
			if ($this->Milestone->save($milestone['Milestone']))
           	{
				$this->Milestone->unbindModel(array('belongsTo' => array('Batch')));
				$milestones = $this->Milestone->findAllByBatchId(0);
				$this->set('default_milestones', $milestones);
				$this->render('lists', 'ajax');
			}
		}
	}
	
	public function delete($milestone_id) {
		if ($this->Milestone->delete($milestone_id)) {
			$this->Milestone->unbindModel(array('belongsTo' => array('Batch')));
			$milestones = $this->Milestone->findAllByBatchId(0);
			$this->set('default_milestones', $milestones);
			$this->render('lists', 'ajax');
		}
	}
	
	public function done() {
		$this->render('done', 'ajax');
	}
	
	public function addform() {
		$this->render ('addform', 'ajax');
	}
}

?>